package com.asmember;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.json.parsers.JSONParser;
import com.json.parsers.JsonParserFactory;

public class Parser {

	
	static List<String> ips;
	
	@SuppressWarnings("rawtypes")
	public static List<String> parseJSON(String json){
		
		ips = new ArrayList<String>();
		
		JsonParserFactory factory=JsonParserFactory.getInstance();
		JSONParser parser=factory.newJsonParser();
		
		Map jsonData=parser.parseJson(json);
		
		HashMap whoIs = (HashMap) jsonData.get("whois-resources");
		HashMap objects = (HashMap) whoIs.get("objects");
		ArrayList object = (ArrayList) objects.get("object");
		
		for(int i=0; i<object.size(); i++){
			HashMap objectData = (HashMap) object.get(i);
			HashMap primary_key = (HashMap) objectData.get("primary-key");
			ArrayList attribute = (ArrayList) primary_key.get("attribute");
			HashMap attributeData= (HashMap) attribute.get(0);
			ips.add((String) attributeData.get("value"));
			
		}
		return ips;
		
	}
	
}
